package com.item.springAop.aop;

import com.item.springAop.demo;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Arrays;

@Aspect
public class MethodAspect {

    @Pointcut("execution(int com.item.springAop.demo.ts(..))")
    public void pointCut() { }

    @Before("com.item.springAop.aop.MethodAspect.pointCut()")
    public void logStart(JoinPoint joinPoint) {
        System.out.println(joinPoint.getSignature().getName() + " 除法运行,参数是：" + Arrays.asList(joinPoint.getArgs()));
    }

    @After("com.item.springAop.aop.MethodAspect.pointCut()")
    public void logEnd() {
        System.out.println("除法结束");
    }


    @AfterReturning(value = "com.item.springAop.aop.MethodAspect.pointCut()", returning = "result")
    public void logReturn2(JoinPoint joinPoint, Object result) {
        System.out.println(joinPoint.getSignature().getName() + "除法返回" + result);
    }

    @AfterThrowing(value = "com.item.springAop.aop.MethodAspect.pointCut()", throwing = "exception")
    public void logException(Exception exception) {
        System.out.println("除法异常");
    }
}
